package com.zhenzhang.myblog.dao;


import com.zhenzhang.myblog.entity.role.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface UserDao {
    @Select("SELECT id,username,password,admin,head AS headImage,email FROM user WHERE username = #{username}")
    User findUserByUsername(@Param("username") String username);

    @Insert("INSERT INTO user " +
            "(`username`, `password`, `admin`, `head`, `email`)" +
            " VALUES " +
            "(#{username}, #{password}, #{admin}, #{headImage}, #{email})")
    int addUser(User user);

    @Select("SELECT username FROM user WHERE id = #{aid}")
    String getUsernameById(Integer aid);

    @Update("UPDATE user SET head=#{filename} WHERE username = #{username}")
    int setAvatar(@Param("username") String username,@Param("filename") String filename);

    @Update("UPDATE user SET username=#{username},email=#{email} WHERE id=#{id}")
    int updateUser(User user);

    @Select("SELECT head FROM user WHERE username = #{username}")
    String getUserAvatar(String username);

    @Update("UPDATE user SET password = #{password} WHERE username = #{username}")
    void updateUserPassword(User user);
}
